<template>
  <div class="LoginBox">
    <a-form
      :model="formState"
      name="basic"
      :label-col="{ span: 8 }"
      :wrapper-col="{ span: 16 }"
      autocomplete="off"
      @finish="onFinish"
    >
      <a-form-item
        label="Username"
        name="username"
        :rules="[{ required: true, message: 'Please input your username!' }]"
      >
        <a-input v-model:value="formState.username" />
      </a-form-item>
      <a-form-item
        label="Password"
        name="password"
        :rules="[{ required: true, message: 'Please input your password!' }]"
      >
        <a-input-password v-model:value="formState.password" />
      </a-form-item>
      <a-form-item :wrapper-col="{ offset: 8, span: 16 }">
        <a-button type="primary" html-type="submit">Submit</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>
<script setup>
import { userPermissionStore } from "@/stores/user";
import { message } from "ant-design-vue";
import router from "@/router";
const store = userPermissionStore();
const formState = reactive({
  username: "",
  password: ""
});
const onFinish = (values) => {
  store.Login(values).then((res) => {
    if (res.success) {
      router.push("/home");
      console.log("res", res);
      return;
    }
    message.error(res.message);
  });
};
</script>

<style lang="scss" scoped>
.LoginBox {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  height: 300px;
  border: 1px solid #ccc;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 0 10px #ccc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
</style>
